package com.huiminpay.transaction.pay;

import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayTradeWapPayRequest;
import com.alipay.api.response.AlipayTradeWapPayResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

/**
 * @author 王帅坤
 * @date 2021年06月23日11:06
 */
@Controller
public class AliPayController {

    @GetMapping("alipay/index")
    public void index() throws AlipayApiException {

        String gateway = "https://openapi.alipaydev.com/gateway.do";
        String appId = "2021000117676686";
        String privateKey = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDH/gFMsWyE0Q6rw5O5ViY7HehXTRCQ1CxftNGvoJ7yOcSR1BDs8VL45AksXQGTyg1F/0mw1uy9LLi4RHBKCMpcJQcHWDRacCOIJypVI+qj3NPgoSzJtyw0mhbUkiwREe/+Vv8UT/C4UFSc32ctlPv9VXXJrsyAc4wnfH9xhIg7Gvtsy98z8XrJt6ze7P0msn7JE4goc7XabZQjqUGuwOKVrFSWv5S67/RLXFYHXPTYAfsH/Sb61ipHuTRCAbh5BSMl/UXZSbTBCZ3AGTGMO2DRnO7JjSCPBpqXWO1KUSdnW14J5yeeuH24jY5V4SjCmRtNEO3FuM+RHZSASgIkneiBAgMBAAECggEAMmQU7b8SydBnMu4/jYZgcarSfRTE5MkhOSg1YVxGUGAv4FKfxSP1NRM4IH56xEM33vg5GB6/Xdcj4AIWjQD0BA2sXLRj1JnGyiqcJwG6wHkGxeW2hEjsEYD12a/O/KoZX2uKMBMIY1iSSUidFcYhTC65VA0AKCl1Ggnrjq3HKaTrtn95aLlp/Or94nHjtVm9UyO+M+a9n7p7ZW69vMqqv0+cs8n83+ztfDYNxlTLDMOT1zoKqsBhfB1UyNUl+jEV/wOtRwgk1Xee0hpSlGjmYet2D1QWAE/LMYwvfPecXshWUYZ8kvbDZZOrqAoH0NtbqJSbUATWtkqTHAwS8zzVsQKBgQDqVepeMc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GNoRxWdr8rYG5Vw+M+zI56HdAfhxVrPLN7qkQ8nzaOBKh6osvD7pjLzyv8tQ+yih2JtF/CVezn6+1bYQ+ZJnpN/F4tPIFEzAyhtbIlJ1a0blr3Gcpsqw3HlKoI+xjmDM6OIv+LM4Cf0MlnFjVkbhAOA2+m2rbkQOlAWNmvHC9dkSxl/11f+8wIDAQAB";


        AlipayClient alipayClient = new DefaultAlipayClient(gateway,appId,privateKey,"json","GBK",publicKey,"RSA2");
        AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest();

        long out_trade_no = System.currentTimeMillis();

        request.setBizContent("{" +
                "\"subject\":\"华为mate100\"," +
                "\"out_trade_no\":\"333\"," +
                "\"timeout_express\":\"90m\"," +
                out_trade_no+
                "\"total_amount\":99999," +
                "\"quit_url\":\"http://www.taobao.com/product/113714.html\"," +
                "\"product_code\":\"QUICK_WAP_PAY\"" +
                "}");
        AlipayTradeWapPayResponse response = alipayClient.pageExecute(request);
        if(response.isSuccess()){
            System.out.println("调用成功");
        } else {
            System.out.println("调用失败");
        }

    }
}
